package com.weetop.cfw.base.presenter.imp

import com.weetop.cfw.base.presenter.AudioFrequencyPresenter
import com.weetop.cfw.base.view.AudioFrequencyView
import com.weetop.cfw.base.view.BaseView
import com.weetop.cfw.bean.AudioVideoBrowsingRecordBean
import com.weetop.cfw.bean.AudioVideoFilterBean
import com.weetop.cfw.callback.RxJavaCallBack
import com.weetop.cfw.mine.activity.AudioFrequencyActivity
import com.weetop.cfw.utils.RetrofitUtils
import com.weetop.cfw.utils.RxJavaUtils

class AudioFrequencyPresenterImp(var audioFrequencyView: AudioFrequencyView? = null): AudioFrequencyPresenter {
    /**
     * 获取管理音频筛选分类数据
     */
    override fun getAudioFrequencyFilterData(audioFrequencyActivity: AudioFrequencyActivity) {
        RxJavaUtils.useInAppCompatActivityOnDestory(RetrofitUtils.getApi().getAudioFilterData(),audioFrequencyActivity,object:
            RxJavaCallBack<AudioVideoFilterBean>(){
            override fun onSuccess(t: AudioVideoFilterBean?) {
                audioFrequencyView?.getAudioFrequencyFilterDataSuccess(t)
            }

            override fun onRequestError(t: AudioVideoFilterBean?) {
                super.onRequestError(t)
                audioFrequencyView?.showNativeShortToast(t?.message)
            }
        })
    }

    /**
     * 获取管理音频数据列表
     */
    override fun getAudioFrequencyDataList(audioFrequencyActivity: AudioFrequencyActivity, classid: Int, key: String, curpage: Int) {
        audioFrequencyActivity.showLoadingDialog(audioFrequencyActivity,"正在获取云课程列表数据...")
        RxJavaUtils.useInAppCompatActivityOnDestory(RetrofitUtils.getApi().getAudioListData(classid = classid,Key = key,curpage = curpage),audioFrequencyActivity,object:RxJavaCallBack<AudioVideoBrowsingRecordBean>(){
            override fun onSuccess(t: AudioVideoBrowsingRecordBean?) {
                audioFrequencyActivity.dismissLoadingDialog()
                audioFrequencyView?.audioFrequencyListDataGetSuccess(t)
            }

            override fun onRequestError(t: AudioVideoBrowsingRecordBean?) {
                super.onRequestError(t)
                audioFrequencyActivity.dismissLoadingDialog()
                audioFrequencyView?.audioFrequencyListDataGetFailed()
            }

            override fun onErrorResponse(throwable: Throwable?) {
                super.onErrorResponse(throwable)
                audioFrequencyActivity.dismissLoadingDialog()
                audioFrequencyView?.audioFrequencyListDataGetFailed()
            }

        })
    }

    /**
     * 绑定
     */
    override fun attachView(baseView: BaseView) {
        audioFrequencyView = baseView as? AudioFrequencyView
    }

    /**
     * 解绑
     */
    override fun detachView() {
        audioFrequencyView = null
    }
}